home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / imc9104.zip / TIMER.C < prev   
Text File  |  1991-03-05  |  3KB  |  90 lines

  1. /*******************************************************************
  2. * TIMER.C - This program times the execution of two functions that *
  3. * reside in the file TESTFUNC.C. You compile TESTFUNC.C using the  *
  4. * type of optimization you wish to test. However, the switches you *
  5. * use to compile this file, TIMER.C, should remain constant for    *
  6. * all tests.                                                       *
  7. *                                                                  *
  8. * To compile without optimization: cl /Ox TIMER.C /Od TESTFUNC.C   *
  9. * To compile with optimization: cl /Ox TIMER.C /Ozax TESTFUNC.C    *
  10. *                                                                  *
  11. * RHS 3/01/91                                                      *
  12. *******************************************************************/
  13. #include<time.h>
  14. #include<process.h>
  15. #include<stdio.h>
  16. #include<stdlib.h>
  17.  
  18. #define DEF_ITERATIONS   10000000L
  19. #define MICROSECONDS     1000000L
  20. #define TRUE 1
  21. #define FALSE 0
  22.  
  23. int testfunc1(void);
  24. int testfunc2(void);
  25. void emptyfunc(void);
  26. void cdecl main(int argc, char **argv);
  27.  
  28. void cdecl main(int argc, char **argv)
  29.     {
  30.     long start = 0L, end = 0L, control_start = 0L, control_end = 0L;
  31.     unsigned long iterations, setting = DEF_ITERATIONS;
  32.     unsigned def = FALSE;
  33.     double test1,test2,empty,op1,op2;
  34.  
  35.     if(argc < 2)
  36.         def = TRUE;
  37.     else
  38.         {
  39.         if(!atol(argv[1]))
  40.             def = TRUE;
  41.         else
  42.             setting = atol(argv[1]);
  43.         }
  44.  
  45.     if(def)
  46.         printf("Testing with default iterations: %lu\n",setting);
  47.     else
  48.         printf("Testing with %lu iterations\n",setting);
  49.  
  50.     puts("Timing empty function...");
  51.     iterations = setting;
  52.     control_start = clock();
  53.     for( ; iterations; iterations--)
  54.         emptyfunc();
  55.     control_end = clock();
  56.     empty = (double)(control_end-control_start);
  57.     empty /= CLOCKS_PER_SEC;
  58.  
  59.     puts("Testing testfunc1...");
  60.     iterations = setting;
  61.     start = clock();
  62.     for( ; iterations; iterations--)
  63.         testfunc1();
  64.     end = clock();
  65.     test1 = (double)(end-start);
  66.     test1 /= CLOCKS_PER_SEC;
  67.      test1 = (test1 < empty) ? empty : test1;
  68.      op1 = (test1 - empty);
  69.  
  70.     puts("Testing testfunc2...");
  71.     iterations = setting;
  72.     start = clock();
  73.     for( ; iterations; iterations--)
  74.         testfunc2();
  75.     end = clock();
  76.     test2 = (double)(end-start);
  77.     test2 /= CLOCKS_PER_SEC;
  78.      test2 = (test2 < empty) ? empty : test2;
  79.      op2 = (test2 - empty);
  80.  
  81.     printf("Test end:\n");
  82.       printf(" Empty function required: %04.5f \n", empty);
  83.      printf("testfunc1 Gross required: %04.5f seconds\n", test1);
  84.      printf("  testfunc1 Net required: %04.5f seconds", op1);
  85.      printf(", %04.5f uSec. each\n", (op1/(setting/MICROSECONDS)));
  86.      printf("testfunc2 Gross required: %04.5f seconds\n", test2);
  87.      printf("  testfunc2 Net required: %04.5f seconds", op2);
  88.      printf(", %04.5f uSec. each\n", (op2/(setting/MICROSECONDS)));
  89.     }
  90.